package com.love.marriage.liveStreamingConfig.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.liveStreamingConfig.entity.LiveStreamingConfig;
import com.love.marriage.liveStreamingConfig.mapper.LiveStreamingConfigMapper;
import com.love.marriage.liveStreamingConfig.service.LiveStreamingConfigService;
import com.love.marriage.liveStreamingConfig.vo.LiveStreamingConfigVo;
import com.love.marriage.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * description:  用户直播配置表服务实现类
 * author:       alex
 * createDate:   2024-12-14 22:52:57
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class LiveStreamingConfigServiceImp extends ServiceImpl<LiveStreamingConfigMapper, LiveStreamingConfig> implements LiveStreamingConfigService {

    private final LiveStreamingConfigMapper liveStreamingConfigMapper;

    @Override
    public Page<LiveStreamingConfigVo> getPage(Long pageNum, Long pageSize, LiveStreamingConfigVo liveStreamingConfigVo) {
        Page<LiveStreamingConfigVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return liveStreamingConfigMapper.getPage(page, liveStreamingConfigVo);
    }

    @Override
    public LiveStreamingConfigVo queryLiveStreamingConfig(Long id) {
        return liveStreamingConfigMapper.queryLiveStreamingConfig(id);
    }

    @Override
    public LiveStreamingConfigVo addLiveStreamingConfig(LiveStreamingConfigVo liveStreamingConfigVo) {
        LiveStreamingConfig liveStreamingConfig = new LiveStreamingConfig();
        BeanUtils.copyProperties(liveStreamingConfigVo, liveStreamingConfig);
        liveStreamingConfigMapper.insert(liveStreamingConfig);
        LiveStreamingConfigVo res = new LiveStreamingConfigVo();
        BeanUtils.copyProperties(liveStreamingConfig, res);
        return res;
    }

    @Override
    public LiveStreamingConfigVo updateLiveStreamingConfig(LiveStreamingConfigVo liveStreamingConfigVo) {
        LiveStreamingConfig liveStreamingConfig = new LiveStreamingConfig();
        BeanUtils.copyProperties(liveStreamingConfigVo, liveStreamingConfig);
        liveStreamingConfigMapper.updateById(liveStreamingConfig);
        return liveStreamingConfigVo;
    }

    @Override
    public Boolean deleteLiveStreamingConfig(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        liveStreamingConfigMapper.deleteBatchIds(idArr);
        return true;
    }
}
